package com.yan.project.service.impl;


import com.yan.core.annotations.Autowired;
import com.yan.core.annotations.Repository;
import com.yan.core.annotations.Service;
import com.yan.core.annotations.Transactional;
import com.yan.project.dao.AccountDao;
import com.yan.project.entity.Account;
import com.yan.project.service.TransferService;

/**
 * @author 应癫
 */
@Service("transferService")
@Transactional
public class TransferServiceImpl implements TransferService {

    @Autowired
    @Repository("accountDao")
    private AccountDao accountDao;

    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {
        System.out.println("开始转账");
        Account from = accountDao.queryAccountByCardNo(fromCardNo);
        Account to = accountDao.queryAccountByCardNo(toCardNo);

        from.setMoney(from.getMoney() - money);
        to.setMoney(to.getMoney() + money);

        accountDao.updateAccountByCardNo(to);
//        int i = 1 / 0;
        accountDao.updateAccountByCardNo(from);
        System.out.println("转账成功");
    }
}
